package yeepay

import (
	"github.com/gin-gonic/gin"
	"github.com/goccy/go-json"
	"github.com/shopspring/decimal"
	"github.com/yop-platform/yop-go-sdk/yop/utils"
	"simplifly-tech/payment/consts"
	"simplifly-tech/payment/internal"
)

type YeePayService struct {
	Channel          consts.SysIncomeChannel
	AppKey           string
	MchPrivateKey    string
	YeePublicKey     string
	ParentMerchantNo string
	LimitPayType     string
	AggParam         string
	TransactionRate  decimal.Decimal
}

func (yeePayService *YeePayService) RefundNotify(ctx *gin.Context) error {
	//TODO implement me
	panic("implement me")
}

func (yeePayService *YeePayService) Init(
	channel consts.SysIncomeChannel,
	appKey string,
	mchPrivateKey string,
	yeePublicKey string,
	parentMerchantNo string,
	aggParam string,
	transactionRate decimal.Decimal,
) {
	yeePayService.Channel = channel
	yeePayService.AppKey = appKey
	yeePayService.MchPrivateKey = mchPrivateKey
	yeePayService.YeePublicKey = yeePublicKey
	yeePayService.ParentMerchantNo = parentMerchantNo
	yeePayService.TransactionRate = transactionRate

	if aggParam != "" {
		yeePayService.AggParam = aggParam
	}
}

func (yeePayService *YeePayService) decrypt(callback string) (internal.YeepayDataRequest, error) {
	content, err := utils.DecryptCallback(yeePayService.YeePublicKey, yeePayService.MchPrivateKey, callback)
	var yeepayData internal.YeepayDataRequest
	if nil != err {
		return yeepayData, err
	}
	err = json.Unmarshal([]byte(content), &yeepayData)
	return yeepayData, err
}

func (yeePayService *YeePayService) GetExchangeRate(buyCurrency, sellCurrency string) (decimal.Decimal, error) {
	return decimal.NewFromInt(1), nil
}
